package com.xszx.business.controller.admin;

import com.xszx.server.dto.AjaxJson;
import com.xszx.server.dto.Page;
import com.xszx.server.entity.Section;
import com.xszx.server.service.SectionService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/section")
@Api(tags = "课程小节管理")
public class SectionController {
    @Resource
    private SectionService sectionService;

    @PostMapping("/getAllSections")
    public Page getAllSections(@RequestBody Page page){
        return sectionService.getAllSections(page);
    }

    @GetMapping("/getSection")
    public AjaxJson getSection(String id){
        return AjaxJson.success().put("sections",sectionService.getSection(id));
    }

    @PostMapping("/save")
    public AjaxJson save(@RequestBody Section section){
        return AjaxJson.success(sectionService.saveOrUpdate(section));
    }
    @GetMapping("/deleteSection")
    public AjaxJson deleteSection(String id){
        int result = sectionService.del(id);
        if(result>0){
            return AjaxJson.success("删除成功");
        }else{
            return AjaxJson.error("删除失败");
        }
    }
}
